<template>
	<view class="components-theme">

		<view>
			<uni-section title="" subTitle="" type="line" style="margin-bottom: 3px;">
				<view class="box-bg">
					<!--适应手机状态栏的高度-->
					<view class="status_bar"
						style="height: var(--status-bar-height); width: 100%; background-color: #245b9f;">
					</view>
					<uni-nav-bar dark @clickLeft="back" color="#eee" backgroundColor="#245b9f" height="44"
						left-icon="left" title="隐患总数" leftText="">
						<block slot="right">
							<view>
								<picker mode="selector" :value="index" :range="range" @change="bindDateChange"
									style="display: inline-block;">
									<view class="uni-input">{{currentYear}}年</view>
									<!-- <view class="uni-input" v-if="">{{year}}年</view> -->
								</picker>
								<u-icon name="arrow-down" color="#fff"
									style="display: inline-block; margin: 5px 5px 5px 5px;"></u-icon>
							</view>
						</block>
					</uni-nav-bar>
				</view>
			</uni-section>
			<view class="uni-list" style="margin-left: 350px;">
				<view class="uni-list-cell">
					<view class="uni-list-cell-db">

					</view>
				</view>
			</view>
		</view>


		<view class="cu-list menu card-menu">
			<!-- 	<view class="box">
				<view class="flex-direction">
					<view class="top">
						隐患总数
						<text class="txt">
							{{dangerListData.hiddenCount}}
							<text class="txtSon"> 条 </text>
						</text>
					</view>
				</view>
			</view> -->

			<view class="box1">
				<view class="charts-box">
					<qiun-data-charts type="arcbar" :opts="opts" :chartData="chartData" />
				</view>
				<view class="charts-box">
					<qiun-data-charts type="arcbar" :opts="opts1" :chartData="chartData1" />
				</view>
				<view class="charts-box">
					<qiun-data-charts type="arcbar" :opts="opts2" :chartData="chartData2" />
				</view>
			</view>

			<view class="box2">
				<text class="txt1">未整改</text>
				<text class="txt2">整改中</text>
				<text class="txt3">已整改</text>
			</view>
		</view>

		<uni-card>
			<view class="bg">
				<text>整改难度</text>
			</view>
			<qiun-data-charts type="column" :opts="opts4" :chartData="chartData4" />
		</uni-card>
	</view>
</template>

<script>
	import {
		dangerList
	} from "@/api/danger.js";
	export default {
		data() {
			return {
				range: [],
				index: 0, // 默认为0
				currentYear: new Date().getFullYear(), //获取当前年份
				dangerListData: {},
				chartData: {},
				chartData1: {},
				chartData2: {},
				chartData4: {},
				opts: {},
				opts1: {},
				opts2: {},
				opts4: {
					padding: [15, 15, 0, 5],
					legend: {
						show: false,
					},
					xAxis: {
						disableGrid: true,
						fontSize: "12",
						fontColor: "#8C8C8C",
					},
					yAxis: {
						data: [{
							min: 0,
							title: "(条)",
						}, ],
						// splitNumber: 4,
						showTitle: true,
						gridType: "dash",
						dashLength: 25,
						height: 233,
					},
					extra: {
						column: {
							type: "group",
							width: 30,
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "custom",
							seriesGap: 5,
							linearOpacity: 0.5,
							customColor: ["#51B4CB", "#185F9A"],
						},
					},
				},
			};
		},

		onLoad() {
			for (let i = this.currentYear - 60; i <= this.currentYear; i++) {
				this.range.push(i)
			}
			this.range.reverse()
		},
		onReady() {
			this.getDangerList(this.currentYear);
		},
		methods: {
			getDangerList(data) {
				dangerList(data)
					.then((result) => {
						this.dangerListData = result.data;
						let options = {
							title: {
								name: this.dangerListData.hiddenStatusCount.notRectified,
								fontSize: 20,
								color: "#343434",
								offsetY: 5,
								offsetX: -5,
							},
							subtitle: {
								name: "条",
								fontSize: 14,
								color: "#343434",
								offsetY: -16,
								offsetX: 20,
							},
							extra: {
								arcbar: {
									type: "circle",
									width: 7,
									backgroundColor: "#C9E2E8",
									startAngle: 1,
									endAngle: 0.25,
									gap: 2,
									linearType: "custom",
									radius: 40,
									centerX: 65,
									centerY: 100,
								},
							},
						}

						let options1 = {
							title: {
								name: this.dangerListData.hiddenStatusCount.underRectification,
								fontSize: 20,
								color: "#343434",
								offsetY: 5,
								offsetX: -5,
							},
							subtitle: {
								name: "条",
								fontSize: 14,
								color: "#343434",
								offsetY: -16,
								offsetX: 20,
							},
							extra: {
								arcbar: {
									type: "circle",
									width: 7,
									backgroundColor: "#C9E2E8",
									startAngle: 1,
									endAngle: 0.25,
									gap: 2,
									linearType: "custom",
									radius: 40,
									centerX: 65,
									centerY: 100,
								},
							},
						}
						let options2 = {
							title: {
								name: this.dangerListData.hiddenStatusCount.rectified,
								fontSize: 20,
								color: "#343434",
								offsetY: 5,
								offsetX: -5,
							},
							subtitle: {
								name: "条",
								fontSize: 14,
								color: "#343434",
								offsetY: -16,
								offsetX: 20,
							},
							extra: {
								arcbar: {
									type: "circle",
									width: 7,
									backgroundColor: "#C9E2E8",
									startAngle: 1,
									endAngle: 0.25,
									gap: 2,
									linearType: "custom",
									radius: 40,
									centerX: 65,
									centerY: 100,
								},
							},
						}

						let res = {
							series: [{
								name: "",
								color: "#185F9A",
								data: this.dangerListData.hiddenStatusCount.notRectified / this
									.dangerListData.hiddenCount,
							}, ],
						};
						let res1 = {
							series: [{
								name: "",
								color: "#185F9A",
								data: this.dangerListData.hiddenStatusCount.underRectification / this
									.dangerListData.hiddenCount,
							}, ],
						};
						let res2 = {
							series: [{
								name: "",
								color: "#185F9A",
								data: this.dangerListData.hiddenStatusCount.rectified / this.dangerListData
									.hiddenCount,
							}, ],
						};
						let res4 = {
							categories: this.dangerListData.hiddenDifficultyCount.x,
							series: [{
								name: "",
								data: this.dangerListData.hiddenDifficultyCount.y,
							}, ],
						};
						this.chartData = JSON.parse(JSON.stringify(res));
						this.chartData1 = JSON.parse(JSON.stringify(res1));
						this.chartData2 = JSON.parse(JSON.stringify(res2));
						this.chartData4 = JSON.parse(JSON.stringify(res4));
						this.opts = options;
						this.opts1 = options1;
						this.opts2 = options2;


					})
					.catch((err) => {
						console.log(err);
					});
			},

			bindDateChange(e) {
				this.currentYear = this.range[e.detail.value]
				this.getDangerList(this.currentYear)
				this.index = e.detail.value // 弹出框关闭以后在出发bindDateChange事件数据还是在上次选择上
			},
			// 自定义菜单点击返回
			back() {
				this.$tab.switchTab("/pages/analyse/index");
				// uni.navigateBack({
				// 	delta: 1
				// })
			}
		},
	};
</script>

<style lang="scss" scoped>
	.components-theme {
		.cu-list {
			border-top: 10rpx solid #eb7738;
			background-color: white;
			margin-top: 36rpx;

			.box {
				background-color: #fafafa;
				border-bottom: 2rpx solid #e5e5e5;
				text-align: center;

				.top {
					display: inline-block;
					font-size: 28rpx;
					font-weight: 600;
					color: #343434;
					margin-top: 48rpx;
					margin-bottom: 50rpx;

					.txt {
						font-size: 60rpx;
						font-style: italic;
						margin-top: 10rpx;
						margin-left: 22rpx;
						color: #329395;

						.txtSon {
							font-size: 30rpx;
							margin-left: 10rpx;
						}
					}
				}
			}

			.box1 {
				display: flex;
				margin-top: -20px;
			}

			.box2 {
				display: flex;

				.txt1 {
					font-size: 28rpx;
					font-weight: 600;
					color: #595959;
					margin-left: 85rpx;
					margin-top: -90rpx;
				}

				.txt2 {
					font-size: 28rpx;
					color: #595959;
					font-weight: 600;
					margin-left: 150rpx;
					margin-top: -90rpx;
				}

				.txt3 {
					font-size: 28rpx;
					font-weight: 600;
					color: #595959;
					margin-left: 150rpx;
					margin-top: -90rpx;
				}
			}
		}

		.bg {
			height: 80rpx;
			line-height: 80rpx;
			padding-left: 20rpx;
			margin-left: -40rpx;
			margin-top: -20rpx;
			background-image: url(../../../static/images/fenxi/jx01.png);
			background-size: 200rpx 80rpx;
			background-repeat: no-repeat;
			color: #185f9a;
			font-size: 32rpx;
			font-weight: 700;
		}
	}

	.charts-box {
		width: 33%;
		height: 200px;
	}


	::v-deep .uni-navbar__header-btns-right[data-v-6bda1a90] {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
		width: 88px !important;
	}

	// #ifdef APP-PLUS
	::v-deep .uni-navbar__header-btns-right[data-v-6bda1a90] {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
		width: 88px !important;
	}

	.box1 {
		.charts-box {
			.sg {
				width: 19%;
				height: 8%;
				position: absolute;
				left: 41%;
				top: 32% !important;
			}
		}
	}

	// #endif


	.u-popup div {
		z-index: 999 !important;
	}
</style>
